package com.shop2cn.iapi.agentproducts.testcase;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.agentproducts.parameter.AddAgentProductBean;
import com.shop2cn.iapi.agentproducts.parameter.ImportAgentProductBean;
import com.shop2cn.iapi.agentproducts.parameter.ProductDetailsDto;
import com.shop2cn.iapi.agentproducts.parameter.ProductListDto;
import com.shop2cn.iapi.agentproducts.parameter.UpdatePriceBean;
import com.shop2cn.iapi.agentproducts.parameter.UpdatePriceDto;
import com.shop2cn.iapi.agentproducts.service.UpdatePriceCall;
import com.ymatou.iapi.godmch.parameter.createDepotBean;
import com.ymatou.iapi.godmch.parameter.setConditionMarkupConfigBean;
import com.ymatou.iapi.godmch.parameter.setShareTypeBean;
import com.ymatou.iapi.notify.parameter.GetMessageListByTimelineNewBean;
import com.ymatou.iapi.notify.parameter.NotifyResModelDto;
import com.ymatou.iapi.notify.parameter.emu.MessageIsNew;
import com.ymatou.iapi.notify.service.GetMessageListByTimelineNewCall;
import com.ymatou.iapi.prodstock.parameter.AgentProductPo;
import com.ymatou.mq.admin.parameter.MessageListBean;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.AddAgentProductCallService;
import com.ymttest.business.service.MqQueryCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.godmch.mch_depot_info;
import com.ymttest.database.sqlwapper.YmtCatalogsIWapper;
import com.ymttest.database.sqlwapper.YmtProductsIWapper;
import com.ymttest.utils.AgentUsers;
import com.ymttest.utils.YMTDateUtil;

/**
 * 修改商品价格 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_UpdatePrice {
	private static UpdatePriceBean updatepriceBean;
	private static UpdatePriceCall updatepriceCall;
	private static YmtCatalogsIWapper ymtCatalogsIWapper = new YmtCatalogsIWapper();
	private static YmtProductsIWapper ymtProductsIWapper = new YmtProductsIWapper();

	// vip渠道
	private static int vipRootUserId = AgentUsers.vipRootUserId;
	private static String vipRootUserName = "NickautoTest";
	// vip渠道->代理
	private static int vipAgentUserId1 = AgentUsers.vipAgentUserId1;
	private static String vipAgentUserName1 = "dgsq408897016";

	// vip渠道->代理->代理
	private static int vipAgentUserId2 = AgentUsers.vipAgentUserId2;
	private static String vipAgentUserName2 = "NickautoTest";

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("修改商品价格");
	}

	@Before
	public void caseUp() {
		updatepriceBean = new UpdatePriceBean();
		updatepriceCall = new UpdatePriceCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(updatepriceCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_UpdatePrice_01() {
		Logger.start(true, "渠道商修改商品价格，所有规格");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(vipRootUserId,
					vipRootUserName, false);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);

			updatepriceBean.setUserId(vipRootUserId);
			updatepriceBean.setProductId(productId);
			List<UpdatePriceDto> updateStockList = new ArrayList<>();
			double price = 20;
			ymtCatalogsIWapper.selectCatalogsByProductId(productId).forEach(p -> {
				UpdatePriceDto updatePriceDto = new UpdatePriceDto();
				updatePriceDto.setCatalogId(p.getsCatalogId());
				updatePriceDto.setSalePrice(price);
				updateStockList.add(updatePriceDto);
			});

			updatepriceBean.setUpdatePriceList(updateStockList);
			updatepriceCall.setData(updatepriceBean);
			updatepriceCall.callService();
			Logger.verifyEquals("200", updatepriceCall.getString("code"), "验证code");
			ymtCatalogsIWapper.selectCatalogsByProductId(productId).forEach(c -> {
				Logger.verifyEquals(price, c.getfQuotePrice().setScale(1).doubleValue(), "验证价格");
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_UpdatePrice_02() {
		Logger.start(true, "渠道商修改商品价格，单规格修改");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(vipRootUserId,
					vipRootUserName, false);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);

			updatepriceBean.setUserId(vipRootUserId);
			updatepriceBean.setProductId(productId);
			List<UpdatePriceDto> updateStockList = new ArrayList<>();
			double price = 20;
			String catalogId = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(0).getsCatalogId();
			String catalogId1 = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(1).getsCatalogId();
			UpdatePriceDto updatePriceDto = new UpdatePriceDto();
			updatePriceDto.setCatalogId(catalogId);
			updatePriceDto.setSalePrice(price);
			updateStockList.add(updatePriceDto);

			updatepriceBean.setUpdatePriceList(updateStockList);
			updatepriceCall.setData(updatepriceBean);
			updatepriceCall.callService();
			Logger.verifyEquals("200", updatepriceCall.getString("code"), "验证code");
			Logger.verifyEquals(price,
					ymtCatalogsIWapper.selectCatalogsByCatalogId(catalogId).getfQuotePrice().setScale(1).doubleValue(),
					"验证价格");
			Logger.verifyEquals(true, ymtCatalogsIWapper.selectCatalogsByCatalogId(catalogId1).getfQuotePrice()
					.setScale(1).doubleValue() != price, "验证价格");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_UpdatePrice_03() {
		Logger.start(true, "vip渠道->vip1，vip1修改价格（修改后价格<拿到的代理价），修改失败");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(vipRootUserId,
					vipRootUserName, true);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);

			ImportAgentProductBean importAgentProductBean = AddAgentProductCallService
					.initImportAgentProduct(vipAgentUserId1, vipAgentUserName1, productId, vipRootUserId, false);
			String agentProductId = AddAgentProductCallService.ImportAgentProduct(importAgentProductBean);

			updatepriceBean.setUserId(vipAgentUserId1);
			updatepriceBean.setProductId(agentProductId);
			List<UpdatePriceDto> updateStockList = new ArrayList<>();
			double price = 100;
			ymtCatalogsIWapper.selectCatalogsByProductId(agentProductId).forEach(p -> {
				UpdatePriceDto updatePriceDto = new UpdatePriceDto();
				updatePriceDto.setCatalogId(p.getsCatalogId());
				updatePriceDto.setSalePrice(price);
				updateStockList.add(updatePriceDto);
			});

			updatepriceBean.setUpdatePriceList(updateStockList);
			updatepriceCall.setData(updatepriceBean);
			updatepriceCall.callService();
			Logger.verifyEquals("201", updatepriceCall.getString("code"), "验证code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_UpdatePrice_04() {
		Logger.start(true, "vip渠道->vip1，vip渠道没有设置代理价,vip渠道修改价格(修改后价格小于下级直销价)，修改成功，发送通知");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(vipRootUserId,
					vipRootUserName, false);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);

			ImportAgentProductBean importAgentProductBean = AddAgentProductCallService
					.initImportAgentProduct(vipAgentUserId1, vipAgentUserName1, productId, vipRootUserId, false);
			String agentProductId = AddAgentProductCallService.ImportAgentProduct(importAgentProductBean);

			updatepriceBean.setUserId(vipRootUserId);
			updatepriceBean.setProductId(productId);
			List<UpdatePriceDto> updateStockList = new ArrayList<>();
			double price = 100;
			ymtCatalogsIWapper.selectCatalogsByProductId(productId).forEach(p -> {
				UpdatePriceDto updatePriceDto = new UpdatePriceDto();
				updatePriceDto.setCatalogId(p.getsCatalogId());
				updatePriceDto.setSalePrice(price);
				updateStockList.add(updatePriceDto);
			});

			updatepriceBean.setUpdatePriceList(updateStockList);
			updatepriceCall.setData(updatepriceBean);
			updatepriceCall.callService();
			Logger.verifyEquals("200", updatepriceCall.getString("code"), "验证code");
			ymtCatalogsIWapper.selectCatalogsByProductId(productId).forEach(c -> {
				Logger.verifyEquals(price, c.getfQuotePrice().setScale(1).doubleValue(), "验证价格");
			});
			Thread.sleep(5000);
			List<NotifyResModelDto> notify = getNotify(vipAgentUserId1);
			boolean hasMsg = false;
			for (NotifyResModelDto notifyResModelDto : notify) {
				if (notifyResModelDto.getMessage().contains(importAgentProductBean.getTitle())) {
					hasMsg = true;
				}

			}
			Logger.verifyEquals(true, hasMsg, "验证发送通知成功");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_UpdatePrice_05() {
		Logger.start(true, "vip渠道->vip1->vip2，vip渠道没有设置代理价,vip渠道修改价格(修改后价格大于下级直销价)，修改成功，发送通知");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(vipRootUserId,
					vipRootUserName, false);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);

			ImportAgentProductBean importAgentProductBean = AddAgentProductCallService
					.initImportAgentProduct(vipAgentUserId1, vipAgentUserName1, productId, vipRootUserId, false);
			String agentProductId = AddAgentProductCallService.ImportAgentProduct(importAgentProductBean);

			ImportAgentProductBean importAgentProductBean1 = AddAgentProductCallService
					.initImportAgentProduct(vipAgentUserId2, vipAgentUserName2, agentProductId, vipAgentUserId1, false);
			String agentProductId2 = AddAgentProductCallService.ImportAgentProduct(importAgentProductBean1);

			updatepriceBean.setUserId(vipRootUserId);
			updatepriceBean.setProductId(productId);
			List<UpdatePriceDto> updateStockList = new ArrayList<>();
			double price = 500;
			ymtCatalogsIWapper.selectCatalogsByProductId(productId).forEach(p -> {
				UpdatePriceDto updatePriceDto = new UpdatePriceDto();
				updatePriceDto.setCatalogId(p.getsCatalogId());
				updatePriceDto.setSalePrice(price);
				updateStockList.add(updatePriceDto);
			});

			updatepriceBean.setUpdatePriceList(updateStockList);
			updatepriceCall.setData(updatepriceBean);
			updatepriceCall.callService();
			Logger.verifyEquals("200", updatepriceCall.getString("code"), "验证code");
			Thread.sleep(2000);
			ymtCatalogsIWapper.selectCatalogsByProductId(productId).forEach(c -> {
				Logger.verifyEquals(price, c.getfQuotePrice().setScale(1).doubleValue(), "验证价格");
			});
			List<NotifyResModelDto> notify = getNotify(vipAgentUserId1);
			Logger.verifyEquals(true, notify.get(0).getMessage().contains(importAgentProductBean.getTitle()),
					"验证发送通知成功");
			// vip1商品待完善状态
			AgentProductPo agentProductPo = ymtProductsIWapper.selectAgentProductByProductId(agentProductId);
			Logger.verifyEquals(0, agentProductPo.getInfoProgress(), "验证下级商品是正常状态");

			// vip2商品删除
			AgentProductPo agentProductPo1 = ymtProductsIWapper.selectAgentProductByProductId(agentProductId2);
			Logger.verifyEquals(0, agentProductPo1.getAction(), "验证vip2商品是正常状态");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_UpdatePrice_06() {
		Logger.start(true, "渠道商修改商品价格，价格小于0，修改失败");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(vipRootUserId,
					vipRootUserName, false);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);

			updatepriceBean.setUserId(vipRootUserId);
			updatepriceBean.setProductId(productId);
			List<UpdatePriceDto> updateStockList = new ArrayList<>();
			double price = -1;
			ymtCatalogsIWapper.selectCatalogsByProductId(productId).forEach(p -> {
				UpdatePriceDto updatePriceDto = new UpdatePriceDto();
				updatePriceDto.setCatalogId(p.getsCatalogId());
				updatePriceDto.setSalePrice(price);
				updateStockList.add(updatePriceDto);
			});

			updatepriceBean.setUpdatePriceList(updateStockList);
			updatepriceCall.setData(updatepriceBean);
			updatepriceCall.callService();
			Logger.verifyEquals("400", updatepriceCall.getString("code"), "验证code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_UpdatePrice_07() {
		Logger.start(true, "渠道商修改商品价格，规格不存在，修改失败");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(vipRootUserId,
					vipRootUserName, false);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);

			updatepriceBean.setUserId(vipRootUserId);
			updatepriceBean.setProductId(productId);
			List<UpdatePriceDto> updateStockList = new ArrayList<>();
			double price = 100;
			ymtCatalogsIWapper.selectCatalogsByProductId(productId).forEach(p -> {
				UpdatePriceDto updatePriceDto = new UpdatePriceDto();
				updatePriceDto.setCatalogId(p.getsCatalogId() + 1);
				updatePriceDto.setSalePrice(price);
				updateStockList.add(updatePriceDto);
			});
			updatepriceBean.setUpdatePriceList(updateStockList);
			updatepriceCall.setData(updatepriceBean);
			updatepriceCall.callService();
			Logger.verifyEquals("201", updatepriceCall.getString("code"), "验证code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_UpdatePrice_08() {
		Logger.start(true, "代理商品修改被动待完善商品价格，回复正常状态");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(vipRootUserId,
					vipRootUserName, false);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);

			ImportAgentProductBean importAgentProductBean = AddAgentProductCallService
					.initImportAgentProduct(vipAgentUserId1, vipAgentUserName1, productId, vipRootUserId, false);
			String agentProductId = AddAgentProductCallService.ImportAgentProduct(importAgentProductBean);

			ImportAgentProductBean importAgentProductBean1 = AddAgentProductCallService
					.initImportAgentProduct(vipAgentUserId2, vipAgentUserName2, agentProductId, vipAgentUserId1, false);
			String agentProductId2 = AddAgentProductCallService.ImportAgentProduct(importAgentProductBean1);

			updatepriceBean.setUserId(vipRootUserId);
			updatepriceBean.setProductId(productId);
			List<UpdatePriceDto> updateStockList = new ArrayList<>();
			double price = 210;
			ymtCatalogsIWapper.selectCatalogsByProductId(productId).forEach(p -> {
				UpdatePriceDto updatePriceDto = new UpdatePriceDto();
				updatePriceDto.setCatalogId(p.getsCatalogId());
				updatePriceDto.setSalePrice(price);
				updateStockList.add(updatePriceDto);
			});

			updatepriceBean.setUpdatePriceList(updateStockList);
			updatepriceCall.setData(updatepriceBean);
			updatepriceCall.callService();
			Logger.verifyEquals("200", updatepriceCall.getString("code"), "验证code");
			Thread.sleep(2000);
			ymtCatalogsIWapper.selectCatalogsByProductId(productId).forEach(c -> {
				Logger.verifyEquals(price, c.getfQuotePrice().setScale(1).doubleValue(), "验证价格");
			});
			List<NotifyResModelDto> notify = getNotify(vipAgentUserId1);
			Logger.verifyEquals(true, notify.get(0).getMessage().contains(importAgentProductBean.getTitle()),
					"验证发送通知成功");
			// vip1商品待完善状态
			AgentProductPo agentProductPo = ymtProductsIWapper.selectAgentProductByProductId(agentProductId);
			Logger.verifyEquals(0, agentProductPo.getInfoProgress(), "验证下级商品是待完善状态");

			// vip2商品删除
			AgentProductPo agentProductPo1 = ymtProductsIWapper.selectAgentProductByProductId(agentProductId2);
			Logger.verifyEquals(0, agentProductPo1.getAction(), "验证vip2商品是删除状态");

			List<UpdatePriceDto> updateStockList1 = new ArrayList<>();
			double price1 = 250;
			ymtCatalogsIWapper.selectCatalogsByProductId(agentProductId).forEach(p -> {
				UpdatePriceDto updatePriceDto = new UpdatePriceDto();
				updatePriceDto.setCatalogId(p.getsCatalogId());
				updatePriceDto.setSalePrice(price1);
				updateStockList1.add(updatePriceDto);
			});

			updatepriceBean.setUpdatePriceList(updateStockList1);
			updatepriceBean.setProductId(agentProductId);
			updatepriceBean.setUserId(vipAgentUserId1);
			updatepriceCall.setData(updatepriceBean);
			updatepriceCall.callService();
			Logger.verifyEquals("200", updatepriceCall.getString("code"), "验证code");
			Thread.sleep(2000);
			ymtCatalogsIWapper.selectCatalogsByProductId(agentProductId).forEach(c -> {
				Logger.verifyEquals(price1, c.getfQuotePrice().setScale(1).doubleValue(), "验证价格");
			});
			List<NotifyResModelDto> notify1 = getNotify(vipAgentUserId2);
			Logger.verifyEquals(true, notify1.get(0).getMessage().contains(importAgentProductBean1.getTitle()),
					"验证发送通知成功");
			// vip1商品待完善状态
			AgentProductPo agentProductPo2 = ymtProductsIWapper.selectAgentProductByProductId(agentProductId);
			Logger.verifyEquals(0, agentProductPo2.getInfoProgress(), "验证下级商品是正常状态");

			// vip2商品删除
			AgentProductPo agentProductPo3 = ymtProductsIWapper.selectAgentProductByProductId(agentProductId2);
			Logger.verifyEquals(0, agentProductPo3.getAction(), "验证vip2商品是正常状态");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_UpdatePrice_09() {
		Logger.start(true, "被动待完善商品修改价格，修改失败");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(vipRootUserId,
					vipRootUserName, false);
			addAgentProductBean.getCatalogList().forEach(p -> {
				p.setDirectPrice(0d);
			});
			addAgentProductBean.setSaleType(2);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Thread.sleep(2000);

			updatepriceBean.setUserId(vipRootUserId);
			updatepriceBean.setProductId(productId);
			List<UpdatePriceDto> updateStockList = new ArrayList<>();
			double price = 210;
			ymtCatalogsIWapper.selectCatalogsByProductId(productId).forEach(p -> {
				UpdatePriceDto updatePriceDto = new UpdatePriceDto();
				updatePriceDto.setCatalogId(p.getsCatalogId());
				updatePriceDto.setSalePrice(price);
				updateStockList.add(updatePriceDto);
			});

			updatepriceBean.setUpdatePriceList(updateStockList);
			updatepriceCall.setData(updatepriceBean);
			updatepriceCall.callService();
			Logger.verifyEquals("200", updatepriceCall.getString("code"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_UpdatePrice_010() {
		Logger.start(true, "渠道商修改商品价格，单规格修改");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(vipRootUserId,
					vipRootUserName, false);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);

			updatepriceBean.setUserId(vipRootUserId);
			updatepriceBean.setProductId(productId);
			List<UpdatePriceDto> updateStockList = new ArrayList<>();
			double price = 20;
			String catalogId = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(0).getsCatalogId();
			String catalogId1 = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(1).getsCatalogId();
			UpdatePriceDto updatePriceDto = new UpdatePriceDto();
			updatePriceDto.setCatalogId(catalogId);
			updatePriceDto.setSalePrice(price);
			updateStockList.add(updatePriceDto);

			updatepriceBean.setUpdatePriceList(updateStockList);
			updatepriceCall.setData(updatepriceBean);
			updatepriceCall.callService();
			Logger.verifyEquals("200", updatepriceCall.getString("code"), "验证code");
			Logger.verifyEquals(price,
					ymtCatalogsIWapper.selectCatalogsByCatalogId(catalogId).getfQuotePrice().setScale(1).doubleValue(),
					"验证价格");
			Logger.verifyEquals(true, ymtCatalogsIWapper.selectCatalogsByCatalogId(catalogId1).getfQuotePrice()
					.setScale(1).doubleValue() != price, "验证价格");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_UpdatePrice_011() {
		Logger.start(true, "渠道商修改商品价格，单价超过一半，价格风控  修改失败");
		try {
			vipRootUserId = GodmchManageCallService.CreateSellerMch();
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(vipRootUserId,
					vipRootUserName, false);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);

			updatepriceBean.setUserId(vipRootUserId);
			updatepriceBean.setProductId(productId);
			List<UpdatePriceDto> updateStockList = new ArrayList<>();
			double price = 10001;
			String catalogId = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(0).getsCatalogId();
			String catalogId1 = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(1).getsCatalogId();
			UpdatePriceDto updatePriceDto = new UpdatePriceDto();
			updatePriceDto.setCatalogId(catalogId);
			updatePriceDto.setSalePrice(price);
			updateStockList.add(updatePriceDto);

			updatepriceBean.setUpdatePriceList(updateStockList);
			updatepriceCall.setData(updatepriceBean);
			updatepriceCall.callService();
			Logger.verifyEquals("400", updatepriceCall.getString("code"), "验证code");
			Logger.verifyIsContains("商品单价超过限额", updatepriceCall.getString("message"), "验证message");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_UpdatePrice_012() {
		Logger.start(true, "无风控的渠道商修改商品价格，单价超过一万， 修改成功");
		try {
			vipRootUserId = GodmchManageCallService.CreateSellerMch();
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(vipRootUserId,
					vipRootUserName, false);
			addAgentProductBean.setCurrency("CNY");
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			updatepriceBean.setUserId(vipRootUserId);
			updatepriceBean.setProductId(productId);
			// 修改限制为20000
			setShareTypeBean initsetShareTypeV2 = GodmchManageCallService.initsetShareTypeV2(vipRootUserId);
			GodmchManageCallService.setShareTypeV2Call(initsetShareTypeV2);
			List<UpdatePriceDto> updateStockList = new ArrayList<>();
			double price = 10001;
			String catalogId = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(0).getsCatalogId();
			String catalogId1 = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(1).getsCatalogId();
			UpdatePriceDto updatePriceDto = new UpdatePriceDto();
			updatePriceDto.setCatalogId(catalogId);
			updatePriceDto.setSalePrice(price);
			updateStockList.add(updatePriceDto);
			// 更新价格--成功
			updatepriceBean.setUpdatePriceList(updateStockList);
			updatepriceCall.setData(updatepriceBean);
			updatepriceCall.callService();
			Logger.verifyEquals("200", updatepriceCall.getString("code"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_UpdatePrice_013() {
		Logger.start(true, "代理商修改商品价格--会撤销标志");
		try {
			int rootUserId = 501475646;
			int agentUserId = 501475647;
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(rootUserId, "",
					true);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Thread.sleep(5000);
			// 查到代理商的商品id
			List<AgentProductPo> ap = ymtProductsIWapper.selectAgentProductByRootProductId(productId).stream()
					.filter(x -> x.getAction() == 0).filter(x -> x.getUserId() == agentUserId)
					.collect(Collectors.toList());
			Logger.debug("ap:" + FormatUtil.beanToGSONString(ap));

			updatepriceBean.setUserId(agentUserId);
			updatepriceBean.setProductId(ap.get(0).getProductId());
			List<UpdatePriceDto> updateStockList = new ArrayList<>();
			double price = 2000;
			ymtCatalogsIWapper.selectCatalogsByProductId(ap.get(0).getProductId()).forEach(p -> {
				UpdatePriceDto updatePriceDto = new UpdatePriceDto();
				updatePriceDto.setCatalogId(p.getsCatalogId());
				updatePriceDto.setSalePrice(price);
				updateStockList.add(updatePriceDto);
			});
			updatepriceBean.setUpdatePriceList(updateStockList);
			updatepriceCall.setData(updatepriceBean);
			updatepriceCall.callService();
			Logger.verifyEquals("200", updatepriceCall.getString("code"), "验证code");
			ymtCatalogsIWapper.selectCatalogsByProductId(ap.get(0).getProductId()).forEach(c -> {
				Logger.verifyEquals(price, c.getfQuotePrice().setScale(1).doubleValue(), "验证价格");
			});

			// 验证价格
			List<ProductListDto> getProductLists2 = AddAgentProductCallService.GetProductLists(agentUserId);
			ProductListDto agentProd = getProductLists2.get(0);
			Logger.verifyEquals(agentProd.getCatalogList().get(0).getDirectPrice(), 2000.0, "验证直销价");

			// 商品打标
			Logger.verifyEquals(agentProd.getAutoMarkupStatus(), 0, "自动加价的标已经取消");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_UpdatePrice_014() {
		Logger.start(true, "渠道商修改商品价格--发送总线--验证使用直销价的代理商的价格");
		try {
			int rootUserId = 500777216;
			int agentUserId = 500777217;
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(rootUserId, "",
					true);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Thread.sleep(5000);
			
			
			// 查到代理商的商品id
			List<AgentProductPo> ap = ymtProductsIWapper.selectAgentProductByRootProductId(productId).stream()
					.filter(x -> x.getAction() == 0).filter(x -> x.getUserId() == agentUserId)
					.collect(Collectors.toList());
			Logger.debug("ap:" + FormatUtil.beanToGSONString(ap));
			String agentProductId = ap.get(0).getProductId();
			updatepriceBean.setUserId(rootUserId);
			updatepriceBean.setProductId(productId);
			List<UpdatePriceDto> updateStockList = new ArrayList<>();
			double price = 200;
			
			ymtCatalogsIWapper.selectCatalogsByProductId(productId).forEach(p -> {
				UpdatePriceDto updatePriceDto = new UpdatePriceDto();
				updatePriceDto.setCatalogId(p.getsCatalogId());
				updatePriceDto.setSalePrice(price);
				updateStockList.add(updatePriceDto);
			});
			updatepriceBean.setUpdatePriceList(updateStockList);
			updatepriceCall.setData(updatepriceBean);
			updatepriceCall.callService();
			Logger.verifyEquals("200", updatepriceCall.getString("code"), "验证code");

			// 验证总线消息
			MessageListBean MessageListBean = MqQueryCallService.initSyncAutoMarkup(agentProductId, agentUserId);
			List<Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
			if (joa.size() == 0) {
				Thread.sleep(5000);
				joa = MqQueryCallService.GetMqMessage(MessageListBean);
			}
			Logger.verifyEquals(joa.size(), 1, "有更新价格的总线消息");
			joa.forEach(ele -> {
				Logger.debug(ele.toString());
			});

			Thread.sleep(5000);

			ProductDetailsDto agentProd = AddAgentProductCallService.selectProductDetails(agentUserId, agentProductId);
			ProductDetailsDto rootProd = AddAgentProductCallService.selectProductDetails(rootUserId, productId);

			// 代理价=直销价
			Logger.verifyEquals(rootProd.getCatalogList().get(0).getDirectPrice(),
					agentProd.getCatalogList().get(0).getDirectPrice(), "验证代理商与渠道商的直销价一致");

			// 商品打标
			Logger.verifyEquals(agentProd.getAutoMarkupStatus(), 1, "已经被打上自动加价的标");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_UpdatePrice_015() {
		Logger.start(true, "渠道商修改商品价格,代理自动加价");
		try {
			Integer mchId = GodmchManageCallService.CreateGodMch();
			Integer agenttype=GodmchManageCallService.getAgentType(mchId, 1);
			Integer agent_mchId = GodmchManageCallService.getAgentMchId(mchId, agenttype);
			createDepotBean bean=GodmchManageCallService.createDepot(mchId);
	        List<mch_depot_info> selectDepotByDepotTitle = GodmchManageCallService.SelectDepotByDepotTitle(bean.getDepotTitle());
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(mchId, "", true);
			addAgentProductBean.setDepotId(selectDepotByDepotTitle.get(0).getDepotId());
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			int percentage=5;
			setConditionMarkupConfigBean setConditionMarkupConfigBean = GodmchManageCallService.initDefSetConditionMarkupConfig(agent_mchId, mchId, percentage, addAgentProductBean, 1);
			//这个case修改的是上级直销价 对应的配置是建议零售价
			setConditionMarkupConfigBean.setMarkupType(2);
			GodmchManageCallService.SetConditionMarkupConfigCall(setConditionMarkupConfigBean);
			List<ProductListDto> getProductLists2 = AddAgentProductCallService.GetProductLists(agent_mchId);
			  int redo=0;
			  while(getProductLists2.size()<1&&redo<3) {
				  Thread.sleep(5000);
				  redo++;
				  getProductLists2 = AddAgentProductCallService.GetProductLists(agent_mchId);
			  }
			ProductListDto agentProd = getProductLists2.get(0);
			//商品打标
			Logger.verifyEquals(agentProd.getAutoMarkupStatus(),1,"已经被打上自动加价的标");

			updatepriceBean.setUserId(mchId);
			updatepriceBean.setProductId(productId);
			List<UpdatePriceDto> updateStockList = new ArrayList<>();
			double price = 300;
			ymtCatalogsIWapper.selectCatalogsByProductId(productId).forEach(p -> {
				UpdatePriceDto updatePriceDto = new UpdatePriceDto();
				updatePriceDto.setCatalogId(p.getsCatalogId());
				updatePriceDto.setSalePrice(price);
				updateStockList.add(updatePriceDto);
			});

			updatepriceBean.setUpdatePriceList(updateStockList);
			updatepriceCall.setData(updatepriceBean);
			updatepriceCall.callService();
			Logger.verifyEquals("200", updatepriceCall.getString("code"), "验证code");
			Thread.sleep(2000);
			getProductLists2 = AddAgentProductCallService.GetProductLists(agent_mchId);
			ProductListDto agentProd2 = getProductLists2.get(0);
			//商品打标
			 redo=0;
			if(agentProd.getCatalogList().get(0).getDirectPrice().equals( agentProd2.getCatalogList().get(0).getDirectPrice() )) {
				Thread.sleep(5000);
				redo++;
				getProductLists2 = AddAgentProductCallService.GetProductLists(agent_mchId);
			}
			BigDecimal sourcedp = new BigDecimal(updateStockList.get(0).getSalePrice()).setScale(2);
//			BigDecimal up=new BigDecimal((percentage+100)).divide(new BigDecimal(100)).setScale(2);
//			BigDecimal newdp = sourcedp.multiply(up).setScale(2,BigDecimal.ROUND_DOWN);
			Logger.verifyEquals(sourcedp, new BigDecimal(agentProd2.getCatalogList().get(0).getDirectPrice()).setScale(2,BigDecimal.ROUND_DOWN),"验证价格");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_UpdatePrice_016() {
		Logger.start(true, "渠道商修改代理价自动加价商品的价格时,代理不会自动加价、因为没有修改代理价");
		try {
			
			Integer mchId = GodmchManageCallService.CreateGodMch();
			Integer agenttype=GodmchManageCallService.getAgentType(mchId, 1);
			Integer agent_mchId = GodmchManageCallService.getAgentMchId(mchId, agenttype);
			createDepotBean bean=GodmchManageCallService.createDepot(mchId);
	        List<mch_depot_info> selectDepotByDepotTitle = GodmchManageCallService.SelectDepotByDepotTitle(bean.getDepotTitle());
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(mchId, "", true);
			addAgentProductBean.setDepotId(selectDepotByDepotTitle.get(0).getDepotId());
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			int percentage=5;
			setConditionMarkupConfigBean setConditionMarkupConfigBean = GodmchManageCallService.initDefSetConditionMarkupConfig(agent_mchId, mchId, percentage, addAgentProductBean, 1);
			//这个case修改的是上级直销价 对应的配置是建议零售价
			setConditionMarkupConfigBean.setMarkupType(2);
			GodmchManageCallService.SetConditionMarkupConfigCall(setConditionMarkupConfigBean);
			List<ProductListDto> getProductLists2 = AddAgentProductCallService.GetProductLists(agent_mchId);
			  int redo=0;
			  while(getProductLists2.size()<1&&redo<3) {
				  Thread.sleep(5000);
				  redo++;
				  getProductLists2 = AddAgentProductCallService.GetProductLists(agent_mchId);
			  }
			ProductListDto agentProd = getProductLists2.get(0);
			//商品打标
			Logger.verifyEquals(agentProd.getAutoMarkupStatus(),1,"已经被打上自动加价的标");

			updatepriceBean.setUserId(mchId);
			updatepriceBean.setProductId(productId);
			List<UpdatePriceDto> updateStockList = new ArrayList<>();
			double price = 300;
			ymtCatalogsIWapper.selectCatalogsByProductId(productId).forEach(p -> {
				UpdatePriceDto updatePriceDto = new UpdatePriceDto();
				updatePriceDto.setCatalogId(p.getsCatalogId());
				updatePriceDto.setSalePrice(price);
				updateStockList.add(updatePriceDto);
			});

			updatepriceBean.setUpdatePriceList(updateStockList);
			updatepriceCall.setData(updatepriceBean);
			updatepriceCall.callService();
			Logger.verifyEquals("200", updatepriceCall.getString("code"), "验证code");
			Thread.sleep(2000);
			getProductLists2 = AddAgentProductCallService.GetProductLists(agent_mchId);
			ProductListDto agentProd2 = getProductLists2.get(0);
			//商品打标
			 redo=0;
			if(agentProd.getCatalogList().get(0).getDirectPrice().equals( agentProd2.getCatalogList().get(0).getDirectPrice() )) {
				Thread.sleep(5000);
				redo++;
				getProductLists2 = AddAgentProductCallService.GetProductLists(agent_mchId);
			}
			BigDecimal sourcedp = new BigDecimal(updateStockList.get(0).getSalePrice()).setScale(2);
//			BigDecimal up=new BigDecimal((percentage+100)).divide(new BigDecimal(100)).setScale(2);
//			BigDecimal newdp = sourcedp.multiply(up).setScale(2,BigDecimal.ROUND_DOWN);
			Logger.verifyEquals(sourcedp, new BigDecimal(agentProd2.getCatalogList().get(0).getDirectPrice()).setScale(2,BigDecimal.ROUND_DOWN),"验证价格");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	

	public static List<NotifyResModelDto> getNotify(int userId) throws IOException {
		GetMessageListByTimelineNewBean getmessagelistbytimelinenewBean = new GetMessageListByTimelineNewBean();
		GetMessageListByTimelineNewCall getmessagelistbytimelinenewCall = new GetMessageListByTimelineNewCall();
		getmessagelistbytimelinenewBean.setFromUserId("19000200");
		getmessagelistbytimelinenewBean.setToUserId(userId);
		getmessagelistbytimelinenewBean.setIsNew(MessageIsNew.No);
		getmessagelistbytimelinenewBean.setLongTimeline(YMTDateUtil.getDate().getTime());
		getmessagelistbytimelinenewBean.setMessageCount(20);
		getmessagelistbytimelinenewBean.setIsNotClearUnReadCount(true);
		getmessagelistbytimelinenewCall.setData(getmessagelistbytimelinenewBean);
		getmessagelistbytimelinenewCall.callService();
		List<NotifyResModelDto> notifyResModelDtos = getmessagelistbytimelinenewCall.getResults();
		return notifyResModelDtos;
	}
}